
 
 <!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>产品商户关系表</title>
	<link rel="stylesheet" type="text/css" href="../../rs/plugins/easyui/themes/metro/easyui.css">
	<link rel="stylesheet" type="text/css" href="../../rs/plugins/easyui/themes/icon.css">
	<link href="../../rs/css/bootstrap.min.css" rel="stylesheet">
	<link href="../../rs/plugins/datapicker/datepicker3.css" rel="stylesheet">
	<script type="text/javascript" src="../../rs/plugins/easyui/jquery.min.js"></script>
	<script type="text/javascript" src="../../rs/plugins/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="../../rs/plugins/easyui/locale/easyui-lang-zh_CN.js"></script>
	<script type="text/javascript" src="../../rs/plugins/easyui/datagrid-groupview.js"></script>
	<script src="../../rs/js/jquery.cookie.js"></script>
	<script src="../../rs/js/common_qj.js"></script>
	<link href="../../rs/plugins/select/css/bootstrap-select.css" rel="stylesheet">
	<script type="text/javascript" src="../../rs/plugins/select/js/bootstrap-select.js"></script>
   
	<style>
		html,body{ margin:0px; height:100%;}
	</style>
	<?php
  		require_once('login.php');
 	?>
</head>
<body >
<table id="table" class="easyui-datagrid"  style="width:100%;height:100%;padding: 10px;"
	   data-options="
			rownumbers:true,
			singleSelect:'false',
			method:'get' ,
			toolbar:'#easyui_toolbar',
			fit:true,
			pagination: true,
			pageSize: 100,
       		pageList: [100,150,200],
			fitColumns:true,
	        showFooter:true,
	        ">
	<thead>
	<tr>
		<th data-options="field:'prid',width:30,align:'center'">产品ID</th>
		<th data-options="field:'prname1',width:50,align:'left'">品名</th>
		<th data-options="field:'prpricein',width:30,align:'center'">进价</th>
		<th data-options="field:'prpriceout',width:30,align:'center'">售价</th>
		<th data-options="field:'spid',width:30,align:'left'">供应商ID</th>
		<th data-options="field:'spmc',width:40,align:'left',formatter:sel_gys">供应商名称</th>
	</tr>
	</thead>
</table>

<div id="easyui_toolbar" region="north" border="false"
	 style="height: 45px;padding: 5px 5px; ">
	<div id="tb" class="input-group" style="float: right; margin-right: 10px;width:350px">
		<input type="text" class="form-control" id="searchtext" placeholder="输入搜索关键字" value="">
		<div class="input-group-btn">
			<button type="button" class="btn btn-white dropdown-toggle" onclick="do_search()" style="border-radius: 0px;">
				搜索
			</button>

		</div>
	</div>
</div>


<div id="easyui_toolbar_xg" region="north" border="false"
	 style="height: 45px;padding: 5px 5px; ">
	<div  class="input-group" style="float: right; margin-right: 10px;width:300px">
		<input type="text" class="form-control" id="searchtext1" placeholder="输入搜索关键字" value="">
		<div class="input-group-btn">
			<button type="button" class="btn  dropdown-toggle" onclick="do_search1()" style="height:34px;border-radius: 0px;">
				搜索
			</button>
			<button style="margin-left:5px;border-radius:0px" type="button" class="btn  dropdown-toggle" onclick="save_do()" style="height:34px;border-radius: 0px;">
				选择
			</button>
		</div>
	</div>
</div>
<div style="display: none" id="open_xg">
	<div id="edit_xg">
		<table id="gys" class="easyui-datagrid"  style="width:100%;height:520px;padding: 10px;"
			   data-options="
			rownumbers:true,
			toolbar:'#easyui_toolbar_xg',
			method:'get' ,
			height: 250,
			fit:false,
			fitColumns:true,
			collapsible:true
	        ">
			<thead>
			<tr>
				<th data-options="field:'ck',checkbox:true"></th>
				<th data-options="field:'cuid',align:'center',width:30">ID</th>
				<th data-options="field:'cuname1',align:'left',width:50">供应商名称</th>
				<th data-options="field:'cumomile',align:'center',width:30">联系电话</th>
			</tr>
			</thead>
		</table>

	</div>
</div>




<!--页面加载缓冲图标-->
<div id='loadingDiv' style="position:absolute;z-index:1000;top:0px; left:0px;
	width:100%;height:100%;background:white;text-align: center;">
	<h1 style="top: 30%; position: relative;">
		<img src="../../rs/img/loading-2.gif" /><br>
	</h1>
</div>
<script src="../../rs/plugins/datapicker/bootstrap-datepicker.js"></script>
<script>

	/*页面加载缓冲*/
	function closeLoading() {
		$("#loadingDiv").fadeOut("normal", function () {
			$(this).remove();
		});
	}
	var no;
	$.parser.onComplete = function () {
		if (no) clearTimeout(no);
		no = setTimeout(closeLoading, 1000);
	}

	var sign = URLencode($.cookie('sign'));

	//    日期插件js开始
	$("#data_5 .input-daterange").datepicker({keyboardNavigation: !1, forceParse: !1, autoclose: !0});
	var config = {
		".chosen-select": {},
		".chosen-select-deselect": {allow_single_deselect: !0},
		".chosen-select-no-single": {disable_search_threshold: 10},
		".chosen-select-no-results": {no_results_text: "Oops, nothing found!"},
		".chosen-select-width": {width: "95%"}
	};
	//    日期插件js结束




	$(function(){
		if(sign==="undefined"){
			window.location.href = "login.html";
		}

		var gys_data;
		f_sheard();
		f_gys();
	});




	//加载数据
	// function f_sheard() {
	// 	$('#table').datagrid({
	// 		url: G_url + 'prsp/getslpr?sign='+sign
	// 	});
	// }

	function f_sheard(){
		$.ajax({
			type: "post",
			url:G_url+'prsp/getslpr?sign='+sign,
			data:'sign=' + sign,
			dataType: "json",
			success: function (result){
				$('#table').datagrid({
					data: result
				});
			},
			error: function (XMLHttpRequest, textStatus, errorThrown) {
			}
		});
	}


	// 产品搜索操作
	$('#searchtext').bind('keypress',function(event){
		if(event.keyCode == "13") {
			do_search();
		}
	});

	function do_search(){
		var s=$('#searchtext').val(); //搜索关键词

		if(s==""){
			$('#table').datagrid({
				url: G_url + 'prsp/getslpr?sign='+sign
			});
		}else{
			$('#table').datagrid({
				url: G_url + 'prsp/getslpr?sign='+sign+"&s="+s
			});
		}

		/*$.ajax({
			type: "post",
			url:G_url+'prsp/getslpr_search',
			data:'sign=' + sign+"&s="+s,
			dataType: "json",
			success: function (data){
				$('#table').datagrid({
					data: data.rows
				});
			},
			error: function (XMLHttpRequest, textStatus, errorThrown) {
			}
		});*/
	}


	function transform(obj){
		var arr = [];
		for(var item in obj){
			arr.push(obj[item]);
		}
		return arr;
	}

	// 供应商搜索操作
	 $('#searchtext1').bind('keydown',function(event){
	 	if(event.keyCode == 13) {
	 		do_search1();
		}
	 });
	 function do_search1(){
		 var gjc1=$('#searchtext1').val(); //搜索关键词
		 if(gjc1==""){
	 		$('#gys').datagrid({
				 data: gys_data
			 });
		 }else{
			 var newdata=[];
			 for(var i=0;i<gys_data.rows.length;i++){
	 			str=transform(gys_data.rows[i]).join(',');
	 			row=str.indexOf(gjc1);
				 if(row>=0){
				 newdata.push(gys_data.rows[i]);
				 }
			 }

				 $('#gys').datagrid({
					 data: newdata
				 });
	 }

	 }

	var rid='';
	var prid='';
	var get_row='';
	function sel_gys(value,rowData,rowIndex){
		return "<a onclick='sel_gys1("+(JSON.stringify(rowData))+","+(JSON.stringify(rowIndex))+","+(JSON.stringify(value))+")'>"+value+"</a>";
	}
	function sel_gys1(selData,rowIndex,value){
		get_row=rowIndex;
		rid=selData.rid;
		prid=selData.prid;
		open_modal();

		//已选择的供应商勾选
		var spids=selData.spid;
		var arrspids = spids.split(',');
		for (var i=0;i<arrspids.length-1;i++){
			var cuids=[];
			for (var j=0;j<gys_data.rows.length;j++){
				cuids.push(gys_data.rows[j].cuid);

			}
			var index=jQuery.inArray(arrspids[i], cuids);
			if(index>-1){
				$('#gys').datagrid("selectRow",index);
			}
		}


	}

	function format_xg(value,rowData,rowIndex){
		return "<button style='height: 24px;line-height: 24px;padding: 0px 6px;border-radius: 0px;background-color: #23c6c8;color: #fff;' class='btn' onclick='add_sp("+JSON.stringify(rowData)+");'>添加</button>";
	}

	function open_modal(){
		$("#open_xg").show();
		$('#reset_xg').click();
		layer.open({
			title: "添加供应商",
			type: 1,
      offset: 'rb',
      
      
      area: ['50%', '100%'], //宽高
      shadeClose: true,
			content: $('#edit_xg')
		});

		$('#gys').datagrid({
			data: gys_data.rows
		});
	}

	function f_gys(){
		$.ajax({
			type: "post",
			url:G_url+'prsp/getslcu',
			data:'sign=' + sign,
			dataType: "json",
			success: function (data){
				gys_data=data;
				/*$('#gys').datagrid({
					data: data.rows
				});*/
			},
			error: function (XMLHttpRequest, textStatus, errorThrown) {
			}
		});
	}





	//保存选择的供应商
	function save_do(){
		var selRows = $('#gys').datagrid('getChecked');
		var cuids="";
		var cuname1s="";
		if(selRows.length==0){
			layer.msg("请选择供应商");
			return false;
		}else{
			for(var i=0;i<selRows.length;i++){
				cuids+=selRows[i].cuid+",";
				cuname1s+=selRows[i].cuname1+",";
			}
			$.ajax({
				type: "post",
				url:G_url+'prsp/save?sign='+sign,
				data:'rid=' +rid+"&prid="+prid+"&spid="+cuids+"&spmc="+cuname1s,
				dataType: "json",
				success: function (result){
					if (result.ok) {
						$('#table').datagrid('updateRow', {
							index: get_row,
							row: {
								spid: cuids,
								spmc: cuname1s
							}
						});
						layer.closeAll();
						layer.msg(result.msg);
					}else{
						$("#dlg").dialog("close").dialog();
						layer.msg(result.msg);
					}
				},
				error: function (XMLHttpRequest, textStatus, errorThrown) {
				}
			});
		}
	}

</script>

<script src="../../rs/plugins/layer/layer.min.js"></script>
<script src="../../rs/js/bootstrap.js"></script>
<script src="../../rs/plugins/md5.js"></script>
</body>
</html>
